<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>公告信息</title>
    <link href="css/swiper-5.4.5/swiper.min.css" rel="stylesheet">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/font-awesome.css" rel="stylesheet">
    <link href="css/index.css" rel="stylesheet">
    <link href="css/my.css" rel="stylesheet">
    <link href="css/nav.css" rel="stylesheet">
    <link href="css/notice.css" rel="stylesheet">
    <style>
        [v-cloak]{
            display: none;
        }
        #view-notice-body img{
            width: 400px;
        }
        #view-notice-body iframe{
            width: 400px;
        }
        #notice-box li{
            margin-bottom: 10px;
        }

    </style>
</head>
<body>
<div id="wrapper">
    <!-- 头部-->
    <div style="width: 100%; height: 60px;line-height: 60px;background-color: #333333">
        <div class="container">
            <div class="row">
                <div class="col-md-8">
                    <div style="color: #b3d8ff;font-size: 20px;">电动甄选</div>
                </div>
                <div class="col-md-4" style="text-align: right;color: #EEEEEE;"v-if="user.name">
                    <span style="color: #b3d8ff;margin-right: 20px;">{{user.name}}</span>
                    <a style="color: #EEEEEE" href="javascript:void (0)"@click="logout">退出</a>

                </div>
                <div v-else class="col-md-4"style="text-align: right;">
                    <a style="color: #EEEEEE;margin-right: 10px;" href="/end/page/login.html" target="_blank">登录</a>
                    <a style="color: #EEEEEE" href="/end/page/register.html" target="_blank">注册</a>

                </div>
            </div>
        </div>
    </div>

    <!--导航-->
    <div class="container" style="margin: 5px auto">
        <div style="width: 100%;height: 50px;line-height: 50px">
            <div class="col-md-12">
                <div class="row">
                    <ul style="display: flex;">
                        <li class="nav-item"><a href="index.html">首页</a> </li>
                        <li class="nav-item active"><a href="noticeInfo.html">公告</a> </li>
                        <li class="nav-item"><a href="videoInfo.html">新能源介绍</a> </li>
                        <li class="nav-item"><a href="richTextInfo.html">汽车详细信息</a> </li>
                        <li class="nav-item"><a href="messageInfo.html">论坛</a> </li>
                        <li class="nav-item"><a href="cartInfo.html">购物车</a> </li>
                        <li class="nav-item"><a href="orderInfo.html">订单</a> </li>
                        <li class="nav-item"><a href="commentInfo.html">评价</a> </li>
                        <li class="nav-item"><a href="javascript:void(0);"@click="personalPage">个人信息</a> </li>
                        <li class="nav-item" v-if="isShow"><a href="/end/page/index.html" target="_blank">进入后台系统</a> </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <!--主题开始-->
    <div class="container" style="margin-top: 20px;">
        <div class="col-md-8">
           <div class="panel panel-default">
               <div class="panel-heading">
                   <b>{{currentNotice.name}}</b>
                   <span style="float: right;color: #888888">{{currentNotice.time}}</span>
               </div>
               <div class="panel-body" id="view-notice-body" v-html="currentNotice.content"></div>
           </div>
        </div>
        <div class="col-md-4">
            <div class="panel panel-default" id="notice-box">
                <div class="panel-heading"><b>公告列表</b></div>
                <div class="panel-body">
                    <ul id="notice-item-box">
                        <li v-for="item in noticeList">
                            <a :href="'noticeInfo.html?id='+item.id" v-bind:class="{active:item.isActive}">{{item.name}}</a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>

    </div>

</div>
<script src="js/jquery-1.10.2.js"></script>
<script src="js/swiper-5.4.5/swiper.min.js"></script>
<script src="js/vue2.6.11/axios.js"></script>
<script src="js/vue2.6.11/vue.min.js"></script>
<script src="js/my.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.metisMenu.js"></script>
<script>
    new Vue({
        el:'#wrapper',
        data:{
            user: {},
            isShow: false, //是否显示进入后台管理
            noticeList: [], //公告列表
            currentNotice: {},//当前公告
            currentId: 0,    //当前公告id
        },
        created: function (){
            axios.get("/auth").then(res =>{
               if(res.data.code==='0'){
                   this.user = res.data.data;
                   if (this.user.level !== 3){
                       this.isShow = true;
                   }
               }
            });
            this.currentId = this.getQueryVariable('id');
            this.loadNoticeInfo();

        },

        methods:{

            //获取传来的参数
            getQueryVariable: function (variable) {
                let query = window.location.search.substring(1);
                let vars = query.split("&");
                for (let i=0;i<vars.length;i++){
                    let pair = vars[i].split("=");
                    if (pair[0] === variable){
                        return pair[1];
                    }
                }
                return '1';
            },
            //登出
            logout(){
                axios.get("/logout").then(res =>{
                    if(res.data.code==='0'){
                        location.href ='/front/index.html'
                    }
                });
            },

            //查询所有公告的列表
            loadNoticeInfo(){
                axios.get("/noticeInfo/page/all?pageSize=10").then(res =>{
                    if(res.data.code==='0'){
                       this.noticeList = res.data.data.list;
                       this.noticeList.forEach(item =>{
                           if (parseInt(this.currentId) === item.id){
                               item.isActive =true;
                               this.currentNotice = item;
                           }else {
                               item.isActive = false;
                           }
                       })

                    }
                });
            },


        }
    });
</script>
</body>
</html>